package frontend.parser.syntaxtree;

import frontend.lexer.TKType;
import frontend.parser.syntaxtree.symbol.NonTerminalSymbol;
import frontend.parser.syntaxtree.symbol.TerminalSymbol;

import java.util.List;
import java.util.function.Consumer;

public class FuncFParamNode extends SyntaxNode {
    public BTypeNode type;
    public String ident;
    public List<ConstExpNode> dimensions;
    public int identLineNum = -1;

    @Override
    public void walk(Consumer<TerminalSymbol> terConsumer, Consumer<NonTerminalSymbol> nonTerConsumer) {
        type.walk(terConsumer, nonTerConsumer);

        terConsumer.accept(new TerminalSymbol(TKType.IDENFR, ident));

        if (dimensions!=null) {
            terConsumer.accept(new TerminalSymbol(TKType.LBRACK));
            terConsumer.accept(new TerminalSymbol(TKType.RBRACK));
//            for (var dim : dimensions) {
//                terConsumer.accept(new TerminalSymbol(TKType.LBRACK));
//                dim.walk(terConsumer, nonTerConsumer);
//                terConsumer.accept(new TerminalSymbol(TKType.RBRACK));
//            }
            dimensions.forEach(dimension -> {
                terConsumer.accept(new TerminalSymbol(TKType.LBRACK));
                dimension.walk(terConsumer, nonTerConsumer);
                terConsumer.accept(new TerminalSymbol(TKType.RBRACK));
            });
        }

        nonTerConsumer.accept(new NonTerminalSymbol(this));
    }

    @Override
    public String getType() {
        return "FuncFParam";
    }
}
